package com.nobuyme.box.toy;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;

import com.nobuyme.box.R;
import com.pachong.android.baseuicomponent.fragment.BaseFragment;

/**
 * A simple {@link Fragment} subclass.
 */
public class WebDetailFragment extends BaseFragment {
    WebView webView;
    public WebDetailFragment() {
        // Required empty public constructor
    }



    @Override
    public View createDataView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.fragment_web_detail, container, false);
        webView = (WebView) inflate.findViewById(R.id.webView1);
        String detail = getArguments().getString(ToyIntroduceActivity.KEY_CONTENT);
        setDetail(detail);
        return inflate;
    }

    public static WebDetailFragment newInstance(String content) {
        Bundle args = new Bundle();
        args.putString(ToyIntroduceActivity.KEY_CONTENT, content);
        WebDetailFragment fragment = new WebDetailFragment();
        fragment.setArguments(args);
        return fragment;
    }
    public void setDetail(String detail) {
        if (!TextUtils.isEmpty(detail)) {
            Log.e("detail",detail);

            webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
//            webView.getSettings().setDefaultTextEncodingName("UTF-8");//设置默认为utf-8
            webView.loadDataWithBaseURL(null, detail, "text/html", "utf-8", null);
        }
    }
}
